import request from '@/utils/request'
import type {
  CommonResult,
  PageResult,
  TagVO,
  TagAddRequest,
  TagUpdateRequest,
  TagQueryRequest,
  BaseRequest,
} from '@/types/api'

/**
 * 新增标签
 */
export function addTag(data: TagAddRequest): Promise<CommonResult<number>> {
  return request({
    url: '/tag/add',
    method: 'post',
    data,
  })
}

/**
 * 删除标签
 */
export function deleteTag(data: BaseRequest): Promise<CommonResult<boolean>> {
  return request({
    url: '/tag/delete',
    method: 'post',
    data,
  })
}

/**
 * 更新标签
 */
export function updateTag(data: TagUpdateRequest): Promise<CommonResult<boolean>> {
  return request({
    url: '/tag/update',
    method: 'post',
    data,
  })
}

/**
 * 分页查询标签
 */
export function pageTag(params: TagQueryRequest): Promise<CommonResult<PageResult<TagVO>>> {
  return request({
    url: '/tag/page',
    method: 'get',
    params,
  })
}

/**
 * 获取标签详情
 */
export function getTagById(id: string): Promise<CommonResult<TagVO>> {
  return request({
    url: '/tag/get',
    method: 'get',
    params: { id },
  })
}

